package cn.lqz.bucttrain.mapper;

import cn.lqz.bucttrain.annotations.AutoFill;
import cn.lqz.bucttrain.enums.OperationTypeEnum;
import cn.lqz.bucttrain.pojo.dto.StationPageQueryDTO;
import cn.lqz.bucttrain.pojo.entity.Station;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface StationMapper {

    /**
     * 查询
     * @param stationPageQueryDTO
     * @return
     */
    Page<Station> findBatch(StationPageQueryDTO stationPageQueryDTO);

    /**
     * 查询
     * @param stationId
     * @return
     */
    @Select("select * from station where station_id=#{stationId}")
    Station findByStationId(Long stationId);

    /**
     * 查询
     * @param city
     * @param stationName
     * @return
     */
    @Select("select * from station where city=#{city} and station_name=#{stationName}")
    Station findByCityAndStationName(String city,String stationName);

    /**
     * 根据城市和站点名模糊查询站点id
     * @param city
     * @param stationName
     * @return
     */
    Long findStationIdByCityAndStationName(String city,String stationName);

    /**
     * 删除
     * @param stationId
     */
    @Delete("delete from station where station_id=#{stationId}")
    void deleteStation(Long stationId);

    /**
     * 插入
     * @param station
     */
    @AutoFill(OperationTypeEnum.INSERT)
    void insert(Station station);

    /**
     * 修改
     * @param station
     */
    @AutoFill(OperationTypeEnum.UPDATE)
    void update(Station station);

    /**
     * 获取站点城市列表
     * @return
     */
    @Select("select DISTINCT city from station order by city")
    List<String> findBatchStationCity();

    /**
     * 获取站点名称列表
     * @return
     */
    @Select("select station_name from station order by station_name")
    List<String> findBatchStationName();
}
